package com.admin.util;

import java.io.InputStream;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class JDBCTools {
	public static Connection getConnection() throws Exception {  
       /* Properties properties = new Properties();  
        InputStream inStream = JDBCTools.class.getClassLoader()  
                .getResourceAsStream("jdbc.properties");  
        properties.load(inStream);  */
  
        // 1. ׼����ȡ���ӵ� 4 ���ַ���: user, password, url, jdbcDriver  
        String user = "root";  
        String password = "123456";  
        String url= "jdbc:mysql://192.168.0.216:3306/chaingov";  
        String jdbcDriver="com.mysql.jdbc.Driver";  
  
        // 2. ��������: Class.forName(driverClass)  
        Class.forName(jdbcDriver);  
  
        // 3.��ȡ���ݿ�����  
        Connection connection = (Connection) DriverManager.getConnection(url, user,  
                password);  
        return connection;  
    }  
  
    public static void releaseDB(ResultSet resultSet, Statement statement,  
            Connection connection) {  
  
        if (resultSet != null) {  
            try {  
                resultSet.close();  
            } catch (SQLException e) {  
                e.printStackTrace();  
            }  
        }  
  
        if (statement != null) {  
            try {  
                statement.close();  
            } catch (SQLException e) {  
                e.printStackTrace();  
            }  
        }  
  
        if (connection != null) {  
            try {  
                connection.close();  
            } catch (SQLException e) {  
                e.printStackTrace();  
            }  
        }  
    }  

}
